{extend name="public/base"/} {block name="body"}
<style>
    .mui-row.mui-fullscreen>[class*="mui-col-"] {
        height: 100%;
    }

    .mui-col-xs-3,
    .mui-col-xs-9 {
        overflow-y: auto;
        height: 100%;
    }

    .mui-segmented-control .mui-control-item {
        line-height: 50px;
        width: 100%;
    }

    .mui-control-content {
        display: block;
    }

    .mui-segmented-control.mui-segmented-control-inverted .mui-control-item.mui-active {
        background-color: #fff;
    }
    .mui-toast-container {
        bottom: 50%;
        z-index: 999999999999999999;
    }
    .mui-btn-block{
      padding: 5px;
      border: 1px solid #ccc !important;
      margin: 5px;
      -webkit-appearance: none;
    }
    .active .mui-icon{
      display: block !important;
    }
    .submitbuttonqx {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 2.876712rem;
        background-color: red;
        color: #fff;
        text-align: center;
        text-decoration: none;
        font-size: 0.410959rem;
        font-weight: bold;
        line-height: 1.315068rem;
    }
</style>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/xsd/css/checkout.css" />
<header class="mui-bar mui-bar-nav" style="z-index:7">
			<a class="mui-icon mui-icon-left-nav mui-pull-left" href="{:url('index/index/delivery')}"></a>
			<h1 class="mui-title">确定订单</h1>
</header>
<div class="mui-content" style="    margin-bottom:60px;">
  <div  class="checkout-section" >
      <section class="cart-address" >
          <div class="address-item"   onclick='window.location.href = "{:url('index/address/index')}"'   {empty name="$address['sex']"}style="display: none;"{/empty}>
              <h2 class="address-name" > <b >{$address.name}</b> <span >{eq name="$address['sex']" value='1'}先生{else /}女士{/eq}</span> <span >{$address.tel}</span> </h2>
              <p class="address-detail" >{$address.address}-{$address.house_number}</p> <span class="mui-icon mui-icon-arrowright"></span>  </div>
          <div class="address-item" onclick='window.location.href = "{:url('index/address/add')}"' {notempty name="$address['sex']"}style="display: none;"{/notempty} > 请添加一个收货地址 <span class="mui-icon mui-icon-arrowright"></span> </div>
      </section>

  <br />
  <section class="cart-group checkout-section">
      <ul class="foodlist" style="    margin: 0;">
          {volist name="cartinfo.list" id="vo"}
            <li> <span class="cellname">{$vo.good_name}</span> <span class="cellquantity">x&nbsp;{$vo.num}</span> <span class="celltotal">¥{$vo['num']*$vo['good_price']}</span> </li>
          {/volist}
          {empty name="cartinfo.list"}
            <script>

              window.location.href = "{:url('index/index/index')}"

            </script>
          {/empty}
      </ul>
    <div class="fee" >
        <div >配送费(约{$address.disparity}公里) 满600全城免运费</div>
        <div id="freight" >¥{$address.freight}</div>


    </div>

    <div class="fee" >
        <div >余额支付</div>
        <div >¥{$Request.session.user.balance}</div>
    </div>
    {eq name=":config('is_freight_promot')" value="1"}

    <div class="fee" >
          <div >运费补贴 (活动商品没有运费补贴)<br />(每消费{:config('freight_promot_meet_price')}元,运费补贴{:config('freight_promot_reduce_price')}}元,补贴最高等于运费)</div>
          <div class="fbt">-¥{$subsidy}</div>
    </div>
    {/eq}
    <!-- <div class="fee" >

        {eq name="isMember" value="1"}
        <div>会员折扣 (活动商品没有会员折扣)</div>
        <div>  {:config('member_discount')*10}折</div>
        {else /}
        <div>
          <a href="{:url('index/user/info')}">注册会员</a><span>(会员注册后享受9.7折折扣)</span>
        </div>
        {/eq}
    </div> -->
    <div class="fee" >
        <div >打包费用</div>
        <div >¥{$cartinfo.pack_price}</div>
    </div>
      <div class="total">
          <div> <span>总计 <span id="zj">¥{$cartCountprice+$address.freight}</span>  余额 ¥{$Request.session.user.balance}</span> &nbsp;&nbsp; </div>
          <span>实付<span style="color:red;" id="sf"></span></span>
        </div>
  </section>


  <section class="checkout-section">
    <div class="fee" style='justify-content: flex-start;' >


  <div class="mui-input-row mui-radio mui-left">
      <label>送货上门</label>
      <input type="radio" name="way" {eq name="Think.cookie.way" value='1'}checked{/eq} value="1" />
  </div>
  <div class="mui-input-row mui-radio mui-left">
      <label>到店自提</label>
      <input type="radio" name="way" {eq name="Think.cookie.way" value='2'}checked{/eq} value="2">
  </div><br />
  <!-- <div class="mui-input-row mui-radio mui-left">
      <label>邮寄</label>
      <input type="radio" name="way" {eq name="Think.cookie.way" value='3'}checked{/eq} value="3">
  </div> -->
    </div>

    <ul class="mui-table-view mui-table-view-radio" id="zt_address"  {eq name="Think.cookie.way" value='1'}style="display:none"{/eq} >

    </ul>
    <script id="zt" type="text/html">
        {{each  as value i}}
          <li class="mui-table-view-cell {{value.default==1 ? 'mui-selected':''}} " data-ztid="{{value.id}}">
              <a class="mui-navigate-right">{{value.name}} </a>
          </li>
        {{/each}}
    </script>
  </section>

  <section class="checkout-section">
      <div class="cart-item fee" id="payment" style="    margin: 0;">
        <span>支付方式</span>
        <span class="cartitem-right">
          <i id="paywaytext" style="    font-style: normal;">
          {eq name="Think.cookie.pay" value='1'}微信支付{else /}货到付款{/eq}
          </i>
          <span class="mui-icon mui-icon-arrowright"></span>
        </span>
      </div>



      <aside class="paylist ">
          <header class="paylist-header">支付方式</header>
          <div class="paylist-item  {eq name='Think.cookie.pay' value='1'}active{/eq}" data-payway='1' ><span> 微信支付  </span> <span class="mui-icon mui-icon-checkmarkempty" style="color:#007aff;border: 1px solid;display:none"></span></div>
      </aside>
      <div class="mask "></div>


      <a class="cart-item fee"  id="coupon-item" style="    margin: 0;"> <span>优惠券</span>
        <span class="cartitem-right">
          <i style="    font-style: normal;">
            {empty name="Think.cookie.couponlist_id"}
              请选择优惠券
            {else /}
              {$Think.cookie.couponlist_id|get_table_field="id","price","CouponList"}元优惠券
            {/empty}
          </i>
          <span class="mui-icon mui-icon-arrowright"></span>
        </span>
      </a>
  </section>

  <section class="checkout-section">
    <div class="cart-item fee" id="pstime" style="    margin: 0;" >
      <span>配送时间</span>
       <span class="cartitem-right" id="pssj">
         <i style="    font-style: normal;">
           {empty name="Think.cookie.deliverytime"}
             {eq name='Think.cookie.shopindex' value="index/index/mailindex"}
                明日发货
             {else/}
               请选择配送时间
             {/eq}
           {else /}
             {$Think.cookie.deliverytime|setDeliverytimeText2}
           {/empty}
         </i>

         {eq name='Think.cookie.shopindex' value="index/index/mailindex"}
            <input type="hidden" name="deliverytime"  value='明日发货'  />
         {else/}
           <input type="hidden" name="deliverytime"  value="{$Think.cookie.deliverytime|setDeliverytimeText}"  />
         {/eq}
         <span class="mui-icon mui-icon-arrowright"></span>
       </span>
    </div>
  </section>
    <form  method="post"  action="{:url('index/order/add')}">
      <section class="checkout-section">
      <div class="mui-input-row" style="margin: 10px 5px;">
      					<textarea id="textarea" name="remark" rows="5" placeholder="备注"></textarea>
      				</div>
      </section>
      <input type="hidden" name="index_type" value="1"  />
      <input type="hidden" name="is_tg" value="1"  />
      <input type="hidden" name="group_time" value="{:config('grouptime')}"  />
    </form>

  </div>
  <script id="tpl2" type="text/html">
        <div class="select-time-box">
          <style>.wd50{width:50%!important;}</style>

          {literal}
                     <dl  class="wd50" id="jtdd"> <dt>{{date1}}<span>{{name1}}</span></dt>
                     	 {{if type1==2}}

                     	<dd class="allow" data-text="{{date1}}10:00-13:00送达" data-val="{{date1}},10:00-13:00">
                           	<label for="radio-choice-0">10:30-13:00</label> </dd>
                           	{{/if}}
                         {{each list as value i}}
                           <dd class="allow" data-text="{{date1}}{{value.start_time}}-{{value.end_time}}送达" data-val="{{date1}},{{value.start_time}}-{{value.end_time}}">
                           	<label for="radio-choice-0">{{value.start_time}}-{{value.end_time}} </label> </dd>
                         {{/each}}
                     </dl>
                     {/literal}

 {literal}
            <dl  class="wd50"> <dt>{{date2}}<span>{{name2}}</span></dt>
            	 {{if type2==2}}

            	<dd class="allow" data-text="{{date2}}10:00-13:00送达" data-val="{{date2}},10:00-13:00">
                  	<label for="radio-choice-0">10:30-13:00</label> </dd>
                  	{{/if}}
                {{each list as value i}}
                  <dd class="allow" data-text="{{date2}}{{value.start_time}}-{{value.end_time}}送达" data-val="{{date2}},{{value.start_time}}-{{value.end_time}}">
                  	<label for="radio-choice-0">{{value.start_time}}-{{value.end_time}} </label> </dd>
                {{/each}}
            </dl>
            {/literal}
        </div>
  </script>


  <div class="select-time-mask" onclick="hideDeliveryTime()" style="display: none;"></div>
  <div class="select-time-wrap" id="select-model-01" style="display: none;"></div>

  <nav class="mui-bar mui-bar-tab" style="   border-bottom: none;  background-color: #3d3d3f; ">
      <span style="    color: #fff;font-size: .48rem;line-height: 1.273333rem;padding-left: .266667rem;">待支付 <span id="dzf" style="color:red"></span></span>
      <a href="javascript:" class="submitbutton" style="right: 2.876712rem;" >确定下单</a>
      <a  class="submitbuttonqx qxdd" data-url="{:url('index/index/delivery')}" >取消订单</a>
  </nav>

</div>

{/block}
{block name="script"}

  <script type="text/javascript">
    $(function(){

      //初始化送货方式改变价格
      var wayid =  "{$Think.cookie.way}"
      if(wayid){
        changeprice(wayid)
      }


    //确定下单
    $('.submitbutton').on('tap', function(){
      var deliverytime = $.trim($('[name="deliverytime"]').val())
      if(!deliverytime){
        mui.toast('请选择送货时间！')
        return;
      }
      //window.location.href = "{:url('index/order/add')}"
      $('form').submit()
    })

    $('.qxdd').on('tap', function(){
     var url = $(this).attr('data-url')
     var btnArray = ['否', '是'];
     mui.confirm('您确定要删除该订单吗？', '删除订单', btnArray, function(e) {
       if (e.index == 1) {
           $.post("{:url('index/cart/clear')}", {}, function(data) {
               mui.toast('删除成功！')
               setTimeout(function() {
                 window.location.href= url
               }, 2000);
           }, "json");

       } else {
         return ;
       }
     })
    })


    $('#payment').on('tap', function(){
        $('.paylist').addClass('open');
        $('.paylist').next().addClass('open');
    })
    $('#coupon-item').on('tap', function(){
        window.location.href = "{:url('index/coupon/index')}"
    })
    $('.mask').on('tap', function(){
      $(this).removeClass('open')
      $('.paylist').removeClass('open')
    })
    $('.paylist-item').on('tap', function(){
      var val = $(this).text(),payway = $(this).attr('data-payway')
      $('#paywaytext').text(val)
      $('.paylist').next().removeClass('open')
      $('.paylist').removeClass('open')
      $(this).addClass('active').siblings().removeClass('active')
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'pay', 'val': payway}, function(json, textStatus) {});
    })

    })

    $('[name="fhd"]').on('tap', function(){
      var val = $(this).val()
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'fhd', 'val': val}, function(json, textStatus) {})
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'place_id', 'val': val}, function(json, textStatus) {
        location.reload()
        console.log(111);


      })

      //changeprice(val)

    })
    //自提地点
    $('[name="way"]').on('tap', function(){
      var val = $(this).val()
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'way', 'val': val}, function(json, textStatus) {})
      changeprice(val)

    })
    //自提地点
    $.post("{:url('index/address/getArayacak')}", function(data) {
      var html = template('zt', data);
      $('#zt_address').html(html);
    }, "json");

    $(document).on('tap', '#zt_address li', function(){
        var id = $(this).attr('data-ztid')
        $.getJSON("{:url('index/cart/changecookie')}", {name: 'zt_address', 'val': id}, function(json, textStatus) {});
    })
    $('#pstime').on('tap', function(){
              $(".select-time-mask").show(), $(".select-time-wrap").show();

    })
      showDeliveryTime()
    function showDeliveryTime() {
        var data = {}
            data.jt = new Date(),
            data.jm = data.jt.getMonth()+1,
            data.jd = data.jt.getDate();
            data.rq = data.jm+'-'+data.jd;
            data.mt = new Date();
            data.mt.setDate(data.mt.getDate()+1);//当前日期+几天
            data.mm = data.mt.getMonth()+1; // 月
            data.md = data.mt.getDate();    // 日
            data.rq2 = data.mm+'-'+data.md;
        $.post("{:url('index/index/getDeliveryTime')}", function(da) {
            if(da){
              data.list = da;

              data.name1 = '今天'
             data.name2 = '明天'
             data.date1 = data.rq+'日'
             data.date2 = data.rq2+'日'

            }

            data.list = [{id: 10, start_time: "13:00", end_time: "18:00", limit_num: 10, type: 0},{id: 11, start_time: "18:00", end_time: "22:00", limit_num: 10, type: 0}]
              // data.name2 = "{:config('grouptime')} 配送"
              var html = template('tpl2', data);
              $('.select-time-wrap').html(html);


              var times = new Date().getHours()+0.1;

              $('#jtdd').find('dd').each(function(){

                //var start = $(this).attr('data-start')
               var start="13:00";
                if(times>= parseInt(start)){
                  $(this).removeClass('allow').addClass('forbidden').removeAttr('onclick').click(function(){
                       mui.toast("亲1，已经过了送货时间，请选择别的时间段~")
                  })
                }
              })




        }, "json");

    }
    $(document).on('tap', '.select-time-box dd.allow',function(){
      var $this = $(this),text = $this.attr('data-text'),val = $this.attr('data-val')
        $('#pssj i').text(text)
        $('#pssj input').val(val)
        $(".select-time-wrap").hide(), $(".select-time-mask").hide()

        $.getJSON("{:url('index/cart/changecookie')}", {name: 'deliverytime', 'val': val}, function(json, textStatus) {
   		 });
    })
    function hideDeliveryTime() {
        $(".select-time-mask").hide(), $(".select-time-wrap").hide()
    }

    function changeprice(way_id){
      var cartCountprice = "{$cartCountprice}", balance = "{$Request.session.user.balance}", subsidy = "{$subsidy}"
      var freight = 0  // way = 2  自提免运费

        $('#zt_address').hide();
      if(way_id == 1){
        freight = "{$address.freight|default='0'}"

        $('.fbt').text("-¥{$subsidy}")
      }else if (way_id == 3) {
        //邮寄运费为15
        freight = 15;
      }else if (way_id == 2) {
        $('.fbt').text('-¥0')
          $('#zt_address').show();
      }

      freight = parseFloat(freight)
      cartCountprice = parseFloat(cartCountprice)
      balance = parseFloat(balance)

      //全场满600 免运费
      if(cartCountprice > 600){
        freight = 0
      }

      if(way_id == 1){
        var zj = cartCountprice+freight-subsidy,sf= zj-balance
      }else{
        var zj = cartCountprice+freight,sf= zj-balance
      }






      sf = parseFloat(sf).toFixed(2)

      $('#freight').text("¥"+freight)
      $('#zj').text("¥"+zj);
      $('#sf').text("¥"+sf);
      preferential(sf)



    }
    function  preferential(sf){
      var yhj = "{$Think.cookie.couponlist_id|get_table_field="id","price","CouponList"}"
      if(yhj){
        var dzf =sf-parseInt(yhj)
      }else{
        dzf =sf

        yhj = 0
      }

      $('#dzf').text('¥'+dzf)

      if(sf<0){
        var ye = parseFloat("{$Request.session.user.balance}")+parseFloat(sf)-parseFloat(yhj)
          ye = ye.toFixed(2)
        $('#sf').text('余额支付'+ye)
        $('#dzf').text('余额支付'+ye)

        $('#paywaytext').text('余额支付')
        $('.paylist').remove();
      }

    }


  </script>
{/block}
